package mech;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;

import javax.swing.Timer;

import obj.Projectile;
import play.Things;

/**
 * The move-set list and actions for the game.
 * @author VincentLy
 */
public class CommandList extends HashMap<String,Move>{
	
	private Timer use;
	private Timer bh;
	private int n = 0;
	private int n2 = 0;
	
	public CommandList(){
		super();
		bh = new Timer(20,new ActionListener(){
			public void actionPerformed(ActionEvent e){
				//adding projectiles for the bullet heaven
				if(n2>0){
					Things.newprojectiles.add(new Projectile((float) (Things.player.x()+Things.player.dir()*Things.player.width()*((Math.random()*5)+1)),(float) (Things.player.y()-Things.player.height()*((Math.random()*2)+1)),Things.player.dir()*5,-5,1,true,Things.player));
					n2--;
				}
				else{
					bh.stop();
					Things.player.useBulletHeaven();
				}	
			}
		});
		use = new Timer(100,new ActionListener(){
			public void actionPerformed(ActionEvent e){
				//consecutive bullets
				if(n>0){
					Things.newprojectiles.add(new Projectile(Things.player.x()+Things.player.dir()*Things.player.width()/2,Things.player.y(),Things.player.dir()*10,0,2,false,Things.player));
					n--;
				}
				else
					use.stop();
			}
		});
		Move drop = new Move("ss",100,"Platform drop",200);
		Move dashLeft = new Move("aa",250,"Dash left",200);
		Move dashRight = new Move("dd",250,"Dash right",200);
		Move bullet = new Move("j",250,"Bullet",250);
		Move bullet1 = new Move("dj",250,"Bullet",250);
		Move bullet2 = new Move("aj",250,"Bullet",250);
		Move bibullet = new Move("sj",500,"2 Bullets",250);
		Move tribulletleft = new Move("saj",750,"3 Bullets",250);
		Move tribulletright = new Move("sdj",750,"3 Bullets",250);
		Move bulletheaven = new Move("k",500,"Bullet Heaven",200);
		Move bulletheaven1 = new Move("dk",500,"Bullet Heaven",200);
		Move bulletheaven2 = new Move("ak",500,"Bullet Heaven",200);
		put(drop.seq(),drop);
		put(dashLeft.seq(),dashLeft);
		put(dashRight.seq(),dashRight);
		put(bullet.seq(),bullet);
		put(bullet1.seq(),bullet1);
		put(bullet2.seq(),bullet2);
		put(bibullet.seq(),bibullet);
		put(tribulletleft.seq(),tribulletleft);
		put(tribulletright.seq(),tribulletright);
		put(bulletheaven.seq(),bulletheaven);
		put(bulletheaven1.seq(),bulletheaven1);
		put(bulletheaven2.seq(),bulletheaven2);
	}
	
	/**
	 * Looks through the dictionary for an action based on the move.
	 * @param m - the move
	 * @author VincentLy
	 */
	public void execute(Move m){
		Things.player.stop();
		switch(m.seq()){
		case "ak":
		case "dk":
		case "k":		
			//execute bullet heaven
			Things.player.setXVel(0);
			n2 = 10;
			bh.start();
			break;
		case "ss":
			//execute platform drop
			if(Things.player.platform()!=null && Things.player.platform().isTrans())
				Things.player.setPlatform(null);
			break;
		case "aa":
			//left dash speed setting
			Things.player.setXVel(-75);
			break;
		case "dd":
			//right dash speed setting
			Things.player.setXVel(75);
			break;
		case "aj":
		case "dj":
		case "j":	
			//basic projectile shot
			Things.newprojectiles.add(new Projectile(Things.player.x()+Things.player.dir()*Things.player.width()/2,Things.player.y(),Things.player.dir()*10,0,1,false,Things.player));
			break;
		case "sj":	
			//double bullets
			Things.player.setXVel(0);		
			n = 2;
			use.start();
			break;
		case "saj":
		case "sdj":		
			//triple bullets
			Things.player.setXVel(0);
			n = 3;
			use.start();
			break;
		}
	}
}